package cn.mw.cmdb.entity.cloudWisdom;

import cn.mw.cmdb.entity.DataAuth;
import cn.mw.cmdb.entity.PropertyTypeString;
import cn.mw.cmdb.view.TreeViewObject;
import cn.mw.components.mongodb.anno.AutoId;
import cn.mw.components.mongodb.anno.CMDBProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;

@Data
@Document("mw_cmdbmd_cloud_wisdom_report_rule_info")
@Schema(description = "云智慧上报规则")
public class CloudWisdomReportRuleInfo extends DataAuth {

    @CMDBProperty(searchType = PropertyTypeString.ID, searchPrefix = "_")
    @AutoId
    @Schema(description = "id")
    private String id;

    @Schema(description = "名称")
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    private String ruleName;

    @Schema(description = "源模型Id")
    @CMDBProperty
    private String sourceModelId;

    @Schema(description = "源模型名称")
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    private String sourceModelName;

    @Schema(description = "目标模型Id")
    @CMDBProperty
    private String targetModelId;

    @Schema(description = "目标模型名称")
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    private String targetModelName;

    @Schema(description = "关联上报通道ID")
    @CMDBProperty(searchType = PropertyTypeString.ID)
    private Integer channelId;

    @Schema(description = "关联上报通道名称")
    @CMDBProperty(searchType = PropertyTypeString.ID)
    private String channelName;

    @Schema(description = "同步方式")
    @CMDBProperty
    private String syncMethod;

    @Schema(description = "事件间隔")
    @CMDBProperty
    private Integer syncTime;

    @Schema(description = "间隔单位")
    @CMDBProperty
    private String syncTimeUnit;

    @Schema(description = "字段映射")
    @CMDBProperty
    private List<CloudWisdomPropertyMappingVo> propertyMappingList;

    @Schema(description = "状态")
    @CMDBProperty
    private Boolean status;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "创建人")
    protected String creator;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "创建时间")
    protected String createDate;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "修改人")
    protected String lastUpdatedBy;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "修改时间")
    protected String lastUpdateDate;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "定时任务jobId")
    private Long jobId;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "源模型")
    private TreeViewObject sourceModelInfo;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "源模型")
    private CloudWisdomModelVo targetModelInfo;

    public void setSourceModelInfo(TreeViewObject sourceModelInfo) {
        this.sourceModelInfo = sourceModelInfo;
        if (sourceModelInfo != null) {
            this.sourceModelId = sourceModelInfo.getId();
            this.sourceModelName = sourceModelInfo.getItemName();
        }
    }

    public void setTargetModelInfo(CloudWisdomModelVo targetModelInfo) {
        this.targetModelInfo = targetModelInfo;
        if (targetModelInfo != null) {
            this.targetModelId = targetModelInfo.getModelId();
            this.targetModelName = targetModelInfo.getModelName();
        }
    }
}
